(function (window, $, undefined) { var phoenixSite = window.phoenixSite || (window.phoenixSite = {}); var commentList = phoenixSite.commentList || (phoenixSite.commentList = {}); var _options = {}; var isFrontend = window.$_phoenix == undefined; var log = console.log; $.extend(commentList, { init: function (option) { // if (isFrontend) { // $.extend(_options, option); // } $.extend(_options, option); var _this = $('.' + _options.className); var commentStar = $(".comment-star-class", _this); var starList = $(".comment-starNew", _this); var customerList = $(".customerName", _this); var currStyle = $(_this[0]).find('input[name="commentCurrStyle"]').val(); commentList.commentAssess(commentStar); commentList.commentAssess2(starList); commentList.commentAns(); commentList.commentAdd(_this); commentList.commentUpFile(); commentList.commentSetCustomer(customerList); // 风格3 if (currStyle == '2') { $(document).ready(function () { commentList.commentStyle3($(_this[1])); setTimeout(function () { dispatchEvent(new Event('resize')); $(_this[1]).find('.vis-hide').removeClass('vis-hide'); }, 500) }) } try { var viewer = new Viewer(document.querySelector('.' + _options.className + ' .sitewidget-bd'), { toolbar: true, rotatable: false, scalable: false, filter(selector) { // 选择器过滤 return selector.className.indexOf("showViewer") == -1 ? false : true; } }); console.log(viewer) } catch (e) { } }, commentStyle3: function (Wrap) { Wrap.css('padding', '0 50px'); var mainPicsSlick = null; if (Wrap.find('.noLists').length) { Wrap.find('.custom-arrow').each(function (a, arrowItem) { $(arrowItem).remove(); }) } // 主图片集 mainPicsSlick = Wrap.find(".main-pics").slick({ dots: false, // 显示圆点指示器 infinite: false, //无限循环滚动 slidesToShow: 4, // 显示的幻灯片数量 slidesToScroll: 1, arrows: true, prevArrow: Wrap.find(".prev"), nextArrow: Wrap.find(".next"), responsive: [ { breakpoint: 1250, settings: { slidesToShow: 3 } }, { breakpoint: 1024, settings: { slidesToShow: 2 } }, { breakpoint: 768, settings: { slidesToShow: 1 } } ], }) var timer = null; window.addEventListener('resize', function () { clearTimeout(timer); timer = setTimeout(function () { carouselImgHandle(mainPicsSlick.slick('getSlick').slideWidth - 20); }, 300) }) // 前台执行 if (!window.$_phoenix) { viewMoreHandle(); // 点击详情 Wrap.find(".icon").unbind('click').click(function () { var popCover = Wrap.find('.pop-cover'); var commentPop = Wrap.find(".comment-pop"); var prodPics = Wrap.find('.comment-pop .prod-pics'); Wrap.find('.comment-pop .comment-pop-wrap .right .comment-text').removeAttr('style'); // 弹窗显示 commentPop.show(); popCover.show(); // 蒙层层级 Wrap.parents('#backstage-bodyArea:eq(0)').css("z-index", 10); $('html').css('overflow', 'hidden'); var data = $(this).parents("form").serializeArray(); //弹窗左侧图片 var photos = data.filter(function (item) { if (item.name === 'photoPath') return true; }) var photosStr = ''; photos.forEach(function (item) { if (item.value) { photosStr += '
' } }) prodPics.html(photosStr || '
'); var formData = {}; data.forEach(function (item) { if (item.name !== 'photoPath') formData[item.name] = item.value; }); var timer2 = null; function noProductResize() { clearTimeout(timer2); timer2 = setTimeout(function () { Wrap.find('.imgBox.slick-slide').each(function (i, imgContainer) { resizeImage($(imgContainer)) }) commentContentHightHandle(); }, 200) } var timer3 = null; function productResize() { clearTimeout(timer3); timer3 = setTimeout(function () { Wrap.find('.imgBox.slick-slide').each(function (i, imgContainer) { resizeImage($(imgContainer)) }) }, 200) } if (formData.isExitProduct == '1') { Wrap.find('.comment-pop-box .prod').hide(); window.addEventListener('resize', noProductResize) noProductResize(); } else { Wrap.find('.comment-pop-box .prod').show(); window.addEventListener('resize', productResize); productResize(); var nameHtml = formData.prodUrl ? "" + (formData.prodName || '') + "" : "" + (formData.prodName || '') + "" Wrap.find('.comment-pop-box .name').attr('title', formData.prodName || '').html("" + (formData.prodName || '') + ""); Wrap.find(".comment-pop-box .price .now span:eq(1)").attr('exchangevalue', formData.prodDiscountPrice).html(formData.prodDiscountPrice || 0); Wrap.find('.comment-pop-box .price .raw span:eq(1)').attr('exchangevalue', formData.prodPrice).html(formData.prodPrice || 0); Wrap.find('.comment-pop-box .star-level .star-num').html(formData.prodStarCount || 0) } Wrap.find('.comment-pop-box .commenter').attr('title', formData.prodCommentTitle || '').html(formData.prodCommentTitle || ''); Wrap.find('.comment-pop-box .comment-text').html("" + (formData.prodCommentContent || '') + ""); Wrap.find('.comment-pop-box .star-level .stars .comment-starNew').attr('attr-num', formData.prodRate); Wrap.find('.comment-pop-box .star .comment-starNew').attr('attr-num', formData.commentStar); Wrap.find('.comment-pop-box .prod-img img').attr('src', formData.prodPhoto); // 价格展示权限 var priceEl = Wrap.find('.comment-pop-box .price'); if (formData.funcPayAuth == 'true' && (formData.prodTradeEnabled || (formData.solutionName && formData.solutionName == 'b2c'))) { priceEl.show(); var unit = ''; // Sku if (formData.isSkuProd && formData.isSkuProd == '1') { priceEl.find('.isSkuProd').show(); priceEl.find('.noSkuProd').hide(); var isProdDetailshowProdprice = false; unit = formData.unitType ? formData.unitType : formData.defaultUnit; if ( formData.minPrice && formData.shopProdPrice && (formData.shopProdPrice == formData.minPrice) && formData.maxPrice && formData.shopProdPriceMax && (formData.shopProdPriceMax == formData.maxPrice) ) { isProdDetailshowProdprice = true; } if (isProdDetailshowProdprice) { priceEl.find('.isProdDetailshowProdprice').hide(); } else { priceEl.find('.isProdDetailshowProdprice').show(); var minPrice = priceEl.find('.minPrice'); var maxPrice = priceEl.find('.maxPrice'); if (!!formData.minPrice && (formData.minPrice != formData.maxPrice)) { maxPrice.attr('exchangevalue', formData.maxPrice); maxPrice.text(formData.maxPrice); maxPrice.show(); minPrice.hide(); } else { minPrice.attr('exchangevalue', formData.minPrice); minPrice.text(formData.minPrice); maxPrice.hide(); minPrice.show(); } } var shopProdPriceEl = priceEl.find('.shopProdPrice'); var shopProdPriceMax = priceEl.find('.shopProdPriceMax'); if (!!formData.shopProdPriceMax && (formData.shopProdPrice != formData.shopProdPriceMax)) { shopProdPriceMax.text(formData.shopProdPriceMax); shopProdPriceMax.attr('exchangevalue', formData.shopProdPriceMax); shopProdPriceEl.hide(); shopProdPriceMax.show(); } else { shopProdPriceMax.text(formData.shopProdPriceMax); shopProdPriceMax.attr('exchangevalue', formData.shopProdPriceMax); shopProdPriceMax.hide(); shopProdPriceEl.show(); } (shopProdPriceEl.length && formData.shopProdPrice) && (shopProdPriceEl.attr('exchangevalue', formData.shopProdPrice).text(formData.shopProdPrice)); } else { priceEl.find('.isSkuProd').hide(); priceEl.find('.noSkuProd').show(); var prodPrice = priceEl.find('.prodPrice'); if (formData.prodDiscountPrice && (formData.prodDiscountPrice != formData.prodPrice)) { priceEl.find('.isProdDiscountPrice').show(); prodPrice.attr('exchangevalue', formData.prodPrice); prodPrice.text(formData.prodPrice); var prodDiscountPrice = priceEl.find('.prodDiscountPrice'); prodDiscountPrice.attr('exchangevalue', formData.prodDiscountPrice); prodDiscountPrice.text(formData.prodDiscountPrice); } else { priceEl.find('.isProdDiscountPrice').hide(); prodPrice.attr('exchangevalue', formData.prodPrice); prodPrice.text(formData.prodPrice); } } // 自定义单位 var unitTypeEl = priceEl.find('.unitType'); if (unitTypeEl.length && unit) { unitTypeEl.show().text(unit); } } else { priceEl.hide(); } // 星级 commentList.commentAssess3(Wrap.find('.comment-pop-box .star-level .stars .comment-starNew')); // 产品 commentList.commentAssess2(Wrap.find('.comment-pop-box .star .comment-starNew')); // 评价 // 产品图片 resizeImage(Wrap.find('.comment-pop .right .prod-img')) // 价格单位 try { phoenixSite.payCoinExchange.handleElement($('.comment-pop-box')); } catch (e) { log('The comment list phoenixSite.payCoinExchange.handleElement is error'); } var prodPicsSlick = prodPics.slick({ dots: photos.length > 1, infinite: false, slidesToShow: 1, slidesToScroll: 1, arrows: false, }) // 开启对话框蒙层绑定关闭点击事件 popCover.click(function (event) { event.stopPropagation(); commentPop.hide(); popCover.hide(); prodPics.slick('unslick'); Wrap.parents('#backstage-bodyArea:eq(0)').css("z-index", 7); window.removeEventListener('resize', productResize); window.removeEventListener('resize', noProductResize); $('html').css('overflow', 'auto'); }); // 关闭 Wrap.find('.comment-close').click(function () { popCover.trigger('click') }) }) } // 不存在产品信息时,对评价内容高度处理 function commentContentHightHandle() { var star = Wrap.find('.star'); var commenter = Wrap.find('.commenter'); var left = Wrap.find('.left'); var commentText = Wrap.find('.comment-pop .comment-pop-wrap .right .comment-text'); commentText.css('height', (left.height() - star.height() - commenter.height() - 40) + 'px') // var parentHeight = Wrap.find('.right').height(); // var child = Wrap.find('.right .comment-text'); // var childHeight = child.height(); // var childTopOffset = child.position().top; // child.css('max-height', (parentHeight - childHeight - childTopOffset) + 'px') } // 更多按钮处理 function viewMoreHandle() { if ($('input[name="commentUrl"]').val()) { Wrap.find("footer .more").show().click(function () { var href = $('input[name="commentUrl"]').val(); href && Wrap.find('#commentUrl').attr('href', href).get(0).click(); }) } else { Wrap.find("footer .more").hide(); } } // 轮播图处理 function carouselImgHandle(height) { Wrap.find('.section .main-pics .comment-item').each(function (j, item) { $(item).height(height || $(item).width()); }) } // 弹窗轮播图完全显示处理 function resizeImage(container) { var image = container.find('img'); var containerRatio = container.width() / container.height(); var imageRatio = image.width() / image.height(); if (containerRatio > imageRatio) { var scale = container.height() / image.height(); // 计算垂直方向的缩放比例 applyTransform(image, scale); } else { var scale = container.width() / image.width(); // 计算水平方向的缩放比例 applyTransform(image, scale); } function applyTransform(element, scale) { element.css({ transform: 'scale(' + scale + ')' }); } } }, getUserReview: function (replaceClass, pageNum, serviceName, widgetType, prodId, articleId, pageId, componentId, settingId, relationCommonId, widgetClass) { if (pageNum == undefined || pageNum == 0) { pageNum = '1'; } var ajaxUrl = '/phoenix/admin/component/dynamic/dev/' + componentId + '/' + settingId + '/' + relationCommonId; if ($('.input_logo').text() == 0) { var ajaxOption = { url: ajaxUrl, type: 'post', cache: false, data: { appIsDev: '1', pageNum: pageNum, serviceName: serviceName, widgetType: widgetType, productId: prodId, articleId: articleId, attr_backend_pageId: pageId, componentId: componentId, settingId: settingId, relationCommonId: relationCommonId, widgetClass: widgetClass, htmlName: 'include' }, dataType: 'html' } } else { var ajaxOption = { url: ajaxUrl, type: 'post', cache: false, data: { appIsDev: '1', pageNum: pageNum, serviceName: serviceName, widgetType: widgetType, productId: prodId, articleId: articleId, attr_backend_pageId: pageId, componentId: componentId, settingId: settingId, relationCommonId: relationCommonId, widgetClass: widgetClass, htmlName: 'style_two' }, dataType: 'html' } } $.ajax(ajaxOption).done(function (response, textStatus, jqXHR) { $('.sitewidget-commentList .' + replaceClass).html(response); commentList.init(_options); }).always(function (response, textStatus, jqXHR) { }); }, commentAns: function () { var _this = $('.' + _options.className); var ans = $(".comment-answer", _this); var ansshow = $(".commentans", _this)[0]; ans.on("click", function () { if (ansshow.style.display == "none") { ansshow.style.display = "block"; } else { ansshow.style.display = "none"; } }); }, commentAdd: function (_this) { for (var i = 0; i < 5; i++) { $(".commentans-mark ul li a", _this).parent().attr("class", "fullStar"); } $(".commentans-mark ul li a", _this).on("click", function () { // 判断是全星点还是半星点,修改当前标签的父标签li的class为对应的星星图像 if (parseInt($(this).html()) % 2 == 1) { $(this).parent().attr("class", "fullStar"); $(".comment-star-up", _this).html(((parseInt($(this).html()) + 1) / 2)); } else { $(this).parent().attr("class", "fullStar"); $(".comment-star-up", _this).html((parseInt($(this).html()) / 2)); } // 对前方的星星进行处理,遍历前方的li使背景图均变为全星 var prev = $(this).parent(); for (var i = 0; i <= (parseInt($(this).html()) / 2) - 1; i++) { prev.prev().attr("class", "fullStar"); prev = prev.prev(); } // 对后方星星进行处理,遍历后面的li使背景图均变为空星 var after = $(this).parent(); for (var i = 0; i <= (5 - parseInt($(this).html()) / 2) - 1; i++) { after.next().attr("class", "emptyStar"); after = after.next(); } // 提示文字隐藏 $("#commentForm .commentans_RequireEmptyT").css("display", "none"); }); $(".commentans-clear", _this).on("click", function () { for (var i = 0; i < 5; i++) { $(".commentans-mark ul li a", _this).parent().attr("class", "emptyStar"); $(".comment-star-up", _this).html(0); } }); }, commentAssess: function (star) { var commentAssessLength = star.length; var imgFull = "//a0.leadongcdn.cn/cloud/ipBqjKlqRikSmriiknjn/full1.png"; var imgHalf = "//a0.leadongcdn.cn/cloud/imBqjKlqRikSmriilnjn/half1.png"; var imgEmpty = "//a0.leadongcdn.cn/cloud/iqBqjKlqRikSmriijnjn/empty1.png"; for (var i = 0; i < commentAssessLength; i++) { //var starNum = star[i].innerHTML; var NumDE = $(star[i]).attr('attr-num'); var eng = NumDE.indexOf(','); var lng = NumDE.indexOf('.'); if (NumDE.indexOf(',') > -1) { //德语金额处理‘.’改为‘,’ var starNum = NumDE.replace(",", '.'); } else { var starNum = $(star[i]).attr('attr-num'); } for (var j = 0; j < Math.floor(Number(starNum)); j++) { var pb = document.createElement("b"); pb.style.backgroundImage = "url(" + imgFull + ")"; pb.style.display = "inline-block"; pb.style.width = 15 + "px"; pb.style.height = 15 + "px"; pb.style.marginRight = 3 + "px"; star[i].appendChild(pb); } if (eng > -1 || lng > -1) { var pb = document.createElement("b"); pb.style.backgroundImage = "url(" + imgHalf + ")"; pb.style.display = "inline-block"; pb.style.width = 15 + "px"; pb.style.height = 15 + "px"; pb.style.marginRight = 3 + "px"; star[i].appendChild(pb); } var endStarNum = 5 - Math.ceil(Number(starNum)); for (var k = 0; k < endStarNum; k++) { var pb = document.createElement("b"); pb.style.backgroundImage = "url(" + imgEmpty + ")"; pb.style.display = "inline-block"; pb.style.width = 15 + "px"; pb.style.height = 15 + "px"; pb.style.marginRight = 3 + "px"; star[i].appendChild(pb); } return; //之前星级处理已废除 if (starNum * 2 % 2 == 0 || (starNum - parseInt(starNum) <= 0.22)) { star[i].innerHTML = " "; for (var j = 0; j < parseInt(starNum); j++) { var pb = document.createElement("b"); pb.style.backgroundImage = "url(" + imgFull + ")"; pb.style.display = "inline-block"; pb.style.width = 15 + "px"; pb.style.height = 16 + "px"; pb.style.marginRight = 3 + "px"; star[i].appendChild(pb); } var endStarNum = 5 - starNum; for (var k = 0; k < endStarNum; k++) { var pb = document.createElement("b"); pb.style.backgroundImage = "url(" + imgEmpty + ")"; pb.style.display = "inline-block"; pb.style.width = 15 + "px"; pb.style.height = 16 + "px"; pb.style.marginRight = 3 + "px"; star[i].appendChild(pb); } } else if (starNum * 2 % 2 == 1 || (starNum - parseInt(starNum) <= 0.72 && starNum - parseInt(starNum) >= 0.28)) { star[i].innerHTML = " "; var starNums = parseInt(starNum); for (var j = 0; j < starNums; j++) { var pb = document.createElement("b"); pb.style.backgroundImage = "url(" + imgFull + ")"; pb.style.display = "inline-block"; pb.style.width = 15 + "px"; pb.style.height = 16 + "px"; pb.style.marginRight = 3 + "px"; star[i].appendChild(pb); } var pb = document.createElement("b"); pb.style.backgroundImage = "url(" + imgHalf + ")"; pb.style.display = "inline-block"; pb.style.width = 15 + "px"; pb.style.height = 16 + "px"; pb.style.marginRight = 3 + "px"; star[i].appendChild(pb); var endStarNum = 5 - starNums - 1; for (var k = 0; k < endStarNum; k++) { var pb = document.createElement("b"); pb.style.backgroundImage = "url(" + imgEmpty + ")"; pb.style.display = "inline-block"; pb.style.width = 15 + "px"; pb.style.height = 15 + "px"; pb.style.marginRight = 3 + "px"; star[i].appendChild(pb); } } else if (starNum - parseInt(starNum) >= 0.78) { star[i].innerHTML = " "; starNum++; for (var j = 0; j < parseInt(starNum); j++) { var pb = document.createElement("b"); pb.style.backgroundImage = "url(" + imgFull + ")"; pb.style.display = "inline-block"; pb.style.width = 15 + "px"; pb.style.height = 16 + "px"; pb.style.marginRight = 3 + "px"; star[i].appendChild(pb); } var endStarNum = 5 - parseInt(starNum); for (var k = 0; k < endStarNum; k++) { var pb = document.createElement("b"); pb.style.backgroundImage = "url(" + imgEmpty + ")"; pb.style.display = "inline-block"; pb.style.width = 15 + "px"; pb.style.height = 16 + "px"; pb.style.marginRight = 3 + "px"; star[i].appendChild(pb); } } } }, commentAssess2: function (star) { var commentAssessLength = star.length; var imgFull = "//a0.leadongcdn.cn/cloud/ipBqjKlqRikSmriiknjn/full1.png"; var imgHalf = "//a0.leadongcdn.cn/cloud/imBqjKlqRikSmriilnjn/half1.png"; var imgEmpty = "//a0.leadongcdn.cn/cloud/iqBqjKlqRikSmriijnjn/empty1.png"; for (var i = 0; i < commentAssessLength; i++) { //var starNum = star[i].innerHTML; var NumDE = $(star[i]).attr('attr-num'); if (NumDE.indexOf(',') > -1) { //德语金额处理‘.’改为‘,’ var starNum = NumDE.replace(",", '.'); } else { var starNum = $(star[i]).attr('attr-num'); } star[i].innerHTML = " "; for (var j = 0; j < Math.ceil(Number(starNum)); j++) { var pb = document.createElement("b"); pb.style.backgroundImage = "url(" + imgFull + ")"; pb.style.display = "inline-block"; pb.style.width = 15 + "px"; pb.style.height = 15 + "px"; pb.style.marginRight = 3 + "px"; star[i].appendChild(pb); } var endStarNum = 5 - Math.ceil(Number(starNum)); for (var k = 0; k < endStarNum; k++) { var pb = document.createElement("b"); pb.style.backgroundImage = "url(" + imgEmpty + ")"; pb.style.display = "inline-block"; pb.style.width = 15 + "px"; pb.style.height = 15 + "px"; pb.style.marginRight = 3 + "px"; star[i].appendChild(pb); } } }, // 半星处理 commentAssess3: function (star) { var commentAssessLength = star.length; var imgFull = "//a0.leadongcdn.cn/cloud/ipBqjKlqRikSmriiknjn/full1.png"; var imgHalf = "//a0.leadongcdn.cn/cloud/imBqjKlqRikSmriilnjn/half1.png"; var imgEmpty = "//a0.leadongcdn.cn/cloud/iqBqjKlqRikSmriijnjn/empty1.png"; for (var i = 0; i < commentAssessLength; i++) { //var starNum = star[i].innerHTML; var NumDE = $(star[i]).attr('attr-num'); var eng = NumDE.indexOf(','); var lng = NumDE.indexOf('.'); if (NumDE.indexOf(',') > -1) { //德语金额处理‘.’改为‘,’ var starNum = NumDE.replace(",", '.'); } else { var starNum = $(star[i]).attr('attr-num'); } star[i].innerHTML = ''; for (var j = 0; j < Math.floor(Number(starNum)); j++) { var pb = document.createElement("b"); pb.style.backgroundImage = "url(" + imgFull + ")"; pb.style.display = "inline-block"; pb.style.width = 15 + "px"; pb.style.height = 15 + "px"; pb.style.marginRight = 3 + "px"; star[i].appendChild(pb); } if (eng > -1 || lng > -1) { var pb = document.createElement("b"); pb.style.backgroundImage = "url(" + imgHalf + ")"; pb.style.display = "inline-block"; pb.style.width = 15 + "px"; pb.style.height = 15 + "px"; pb.style.marginRight = 3 + "px"; star[i].appendChild(pb); } var endStarNum = 5 - Math.ceil(Number(starNum)); for (var k = 0; k < endStarNum; k++) { var pb = document.createElement("b"); pb.style.backgroundImage = "url(" + imgEmpty + ")"; pb.style.display = "inline-block"; pb.style.width = 15 + "px"; pb.style.height = 15 + "px"; pb.style.marginRight = 3 + "px"; star[i].appendChild(pb); } } }, commentUpFile: function () { var _this = $('.' + _options.className); var oAdd = $(".comment-label", _this); //添加图片 var oSubmit = $(".commentans-submit", _this); //提交 var oInput = $(".commentans-inputimg", _this)[0]; //文件输入框 var form = $(".commentForm", _this)[0]; //form保单 var Ctitle = $(".commentans-title", _this); //标题 var Ccontent = $(".commentans-content", _this); //内容 var Cstar = $(".comment-star-up", _this)[0]; //评价星级 var commentRequireT = $(".commentRequireT", _this)[0]; //标题验证 var commentRequireC = $(".commentRequireC", _this)[0]; //内容验证 var commentRequireEmptyC = $(".commentRequireEmptyC", _this)[0]; //标题判空验证 var commentRequireEmptyT = $(".commentRequireEmptyT", _this)[0]; //内容盘空验证 var commentFlag = 1; //提交状态吗 var commentCovercolor = $(".comment-covercolor", _this)[0]; //遮罩层 var commentCover = $(".comment-cover", _this)[0]; //提交等待 var commentsuccess = $(".comment-success", _this)[0]; //成功遮罩层 var commentfalse = $(".comment-false", _this)[0]; //失败遮罩层 var commentFalseSpan = $(".comment-false-span", _this)[0]; //失败内容输出 var commentRequirema = $(".commentRequirema", _this)[0]; //验证码cuowu提示 var commentclickre = $(".commentclickre", _this); //点击验证码 var commentinputrequired = $(".commentinputrequired", _this); //验证码输入框 var fileimage = $(".file-image", _this); //选择图片显示 var commentsiximg = $(".comment-siximg", _this)[0]; //选择图片显示 var result; var dataArr = []; // 储存所选图片的结果(文件名和base64数据) var fd; //FormData方式发送请求 if (typeof FileReader === 'undefined') { console.log("抱歉,你的浏览器不支持 FileReader"); oInput.setAttribute('disabled', 'disabled'); } else if (oInput) { oInput.addEventListener('change', readFile, false); } //handler function readFile() { var iLen = this.files.length; var numimg = document.getElementById('file-image').children; var index = 0; for (var i = 0; i < iLen; i++) { var reader = new FileReader(); reader.index = i; //fd.append(i,this.files[i]); reader.readAsDataURL(this.files[i]); //转成base64 reader.fileName = this.files[i].name; reader.onload = function (e) { var imgMsg = { name: this.fileName, //获取文件名 base64: this.result //reader.readAsDataURL方法执行完后,base64数据储存在reader.result里 } if (dataArr.length < 6) { dataArr.push(imgMsg); //console.log(dataArr.length); } result = '
'; var div = document.createElement('div'); //console.log(numimg.length); div.innerHTML = result; div['className'] = 'comment-img-float'; div['index'] = index; if (numimg.length < 6) { document.getElementById('file-image').appendChild(div); commentsiximg.innerHTML = numimg.length + "/6"; } var img = div.getElementsByTagName('img')[0]; img.style.width = 35 + "px"; img.style.height = 35 + "px"; div.onclick = function () { this.remove(); // 在页面中删除该图片元素 delete dataArr[this.index]; // 删除dataArr对应的数据 commentsiximg.innerHTML = (numimg.length) + "/6"; } index++; } } } oAdd.on("click", function () { oInput.value = ""; // 先将oInput值清空,否则选择图片与上次相同时change事件不会触发 }); //输入框判空处理以及字符限制 Ctitle.on("blur", function () { if ($(".commentans-title").val().length > 80) { //console.log("请输入1~80个字符"); commentRequireT.style.display = "block"; Ctitle[0].style.borderColor = "#f00"; commentRequireEmptyT.style.display = "none"; commentFlag = 0; } else { commentRequireT.style.display = "none"; commentRequireEmptyT.style.display = "none"; commentFlag = 1; Ctitle[0].style.borderColor = "#ccc"; } }); Ccontent.on("blur", function () { if ($(".commentans-content").val().length > 3000 || ($(".commentans-content").val().length < 1 && $(".commentans-content").val().length > 0)) { //console.log("请输入1~1000个字符"); commentRequireC.style.display = "block"; commentFlag = 0; commentRequireEmptyC.style.display = "none"; Ccontent[0].style.borderColor = "#f00"; } else { commentRequireC.style.display = "none"; commentRequireEmptyC.style.display = "none"; commentFlag = 1; Ccontent[0].style.borderColor = "#ccc"; } }); oSubmit.on("click", function (e) { oData = new FormData(form); oData.append("commentStar", Cstar.innerHTML); e.preventDefault(); console.log(); if (parseFloat($(Cstar).text()) <= 0) { $("#commentForm .commentans_RequireEmptyT").css("display", "inline-block"); } else if (!Ctitle[0].value) { //console.log("标题不能为空!"); commentRequireEmptyT.style.display = "block"; Ctitle[0].style.borderColor = "#f00"; } else if (!Ccontent[0].value) { //console.log("内容不能为空!"); commentRequireEmptyC.style.display = "block"; Ccontent[0].style.borderColor = "#f00"; } else if (commentFlag == 1) { var submitArr = []; for (var i = 0; i < dataArr.length; i++) { if (dataArr[i]) { submitArr.push(dataArr[i]); } } //base64转成blob function dataURLtoBlob(dataurl) { var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1], bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n); while (n--) { u8arr[n] = bstr.charCodeAt(n); } return new Blob([u8arr], { type: mime }); } for (var i = 0; i < submitArr.length; i++) { blobs = dataURLtoBlob(submitArr[i].base64); oData.append("fileData", blobs, submitArr[i].name); } var oReq = new XMLHttpRequest(); oReq.open("POST", "/phoenix/admin/comment", true); oReq.onreadystatechange = function () { if (oReq.readyState == 4 && oReq.status == 200) { var resData = JSON.parse(oReq.responseText); if (resData.success) { commentCover.style.display = "none"; commentsuccess.style.display = "block"; setTimeout(function () { commentsuccess.style.display = "none"; commentCovercolor.style.display = "none"; }, 1000); Ctitle[0].value = " "; Ccontent[0].value = " "; commentinputrequired[0].value = ""; fileimage[0].innerHTML = " "; commentRequirema.style.display = "none"; commentList.getUserReview(_options.commentParent, _options.pageNum, _options.serviceName, _options.widgetType, _options.prodId, _options.articleId, _options.pageId, _options.componentId, _options.settingId, _options.relationCommonId, _options.className); $(".commentclickre", _this).trigger("click"); } else if (resData.error.typeError) { commentCover.style.display = "none"; commentfalse.style.display = "block"; commentFalseSpan.innerHTML = "评论类型有误"; setTimeout(function () { commentfalse.style.display = "none"; commentCovercolor.style.display = "none"; }, 1000); commentRequirema.style.display = "none"; } else if (resData.error.uploadFailed) { commentCover.style.display = "none"; commentfalse.style.display = "block"; commentFalseSpan.innerHTML = "上传文件失败"; setTimeout(function () { commentfalse.style.display = "none"; commentCovercolor.style.display = "none"; }, 1000); commentRequirema.style.display = "none"; } else if (resData.error.notImage) { commentCover.style.display = "none"; commentfalse.style.display = "block"; commentFalseSpan.innerHTML = "文件类型错误"; setTimeout(function () { commentfalse.style.display = "none"; commentCovercolor.style.display = "none"; }, 1000); commentRequirema.style.display = "none"; } else if (resData.error.noVerifyCode) { commentCover.style.display = "none"; commentCovercolor.style.display = "none"; //commentfalse.style.display="block"; commentRequirema.style.display = "inline-block"; commentclickre.onclick = function () { phoenixSite.faptcha.reload("component_${settingId!}"); return false; } commentinputrequired[0].value = ""; $(".commentclickre", _this).trigger("click"); } } else { //console.log("error"); } } oReq.send(oData); commentCover.style.display = "block"; commentCovercolor.style.display = "block"; } }); }, commentSetCustomer: function (customerList) { // 是否开启隐藏评价人 var _isFlayHide = $(".customerName.hideFlagName"); console.log(_isFlayHide, '测试产品列表………………………………1111111'); if (_isFlayHide.length > 0) { $(customerList).each(function () { var _custName = $(this).text().trim(); var _custLenght = _custName.length; if (_custLenght >= 2) { var _startStr = _custName.substring(0, 1); var _endStr = _custName.substring(_custLenght - 1, _custLenght); _custName = _startStr + "***" + _endStr; } else { _custName += "***"; } $(this).text(_custName); }); } } }); })(window, jQuery)